#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
int v[1010];
int w[1010];
void solve()
{
    int n, V;
    cin >> n >> V;
    for (int i = 0;i < n;i++) cin >> v[i] >> w[i];

    vector<int> dp1(V + 1, 0);
    vector<int> dp2(V + 1, 0);
    for (int i = 1;i <= V;i++) dp2[i] = -1;
    for (int i = 1; i <= n;i++)
    {
        for (int j = v[i - 1];j <= V;j++)
        {
            dp1[j] = max(dp1[j], dp1[j - v[i - 1]] + w[i - 1]);

            if (dp2[j - v[i - 1]] != -1)
                dp2[j] = max(dp2[j], dp2[j - v[i - 1]] + w[i - 1]);

        }
    }

    cout << dp1[V] << endl;
    if (dp2[V] == -1) cout << 0 << endl;
    else cout << dp2[V] << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();
    return 0;
}